#include "common_impl.h"
#include "../import/import.h"
#include "../global/head.h"

////////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos_common
{

    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    common_impl::common_impl()
    {
    }

    common_impl::~common_impl()
    {
        if( g_pSysData )
        {
            g_pSysData->term();
            delete g_pSysData;
            g_pSysData = 0;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    // 
    // create objects
    // 
    int common_impl::create( enumObjType enumType, void ** ppv )
    {
        int nRet = 0;

        *ppv = 0;

        switch( enumType )
        {
        case OBJ_PROPERTY:
            {
                property_impl * p = m_property_pool.GetItem();
                p->init();
                *ppv = p;
            }
            break;
        case OBJ_MD5:
            {
                md5 * p = m_md5_pool.GetItem();
                p->init();
                *ppv = p;
            }
            break;
        case OBJ_MISC:
            {
                misc * p = m_misc_pool.GetItem();
                p->init();
                *ppv = p;
            }
            break;
        case OBJ_SHA:
            {
                sha * p = m_sha_pool.GetItem();
                p->init();
                *ppv = p;
            }
            break;
        }

        if( !( *ppv ) )
        {
            nRet = 1;
        }

        return nRet;
    }

    int common_impl::release()
    {
        int nRet = 0;

        m_property_pool.ReleaseAll();
        m_misc_pool.ReleaseAll();
        m_md5_pool.ReleaseAll();
        m_sha_pool.ReleaseAll();
        
        delete this;

        return nRet;
    }

} // xos_common
